package com.meilingcloud.biobank.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.meilingcloud.biobank.domain.TubeHistory;
import com.meilingcloud.biobank.service.ITubeHistoryService;
import com.meilingcloud.common.annotation.Log;
import com.meilingcloud.common.core.controller.BaseController;
import com.meilingcloud.common.core.domain.AjaxResult;
import com.meilingcloud.common.core.page.TableDataInfo;
import com.meilingcloud.common.enums.BusinessType;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 冻存管历史 Controller
 *
 * @author chenl
 * @date 2021-04-01
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/biobank/tube/history")
public class TubeHistoryController extends BaseController {

    private final ITubeHistoryService iTubeHistoryService;

    /**
     * 查询冻存管历史 列表
     */
    @PreAuthorize("@ss.hasPermi('biobank:container:list')")
    @GetMapping("/list")
    public TableDataInfo list(TubeHistory tubeHistory) {
        startPage();
        List<TubeHistory> list = iTubeHistoryService.list(new LambdaQueryWrapper<TubeHistory>()
                .eq(TubeHistory::getTubeId, tubeHistory.getTubeId()));
        return getDataTable(list);
    }

    /**
     * 新增冻存管历史
     */
    @Log(title = "冻存管历史 ", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TubeHistory tubeHistory) {
        return toAjax(iTubeHistoryService.save(tubeHistory));
    }

    /**
     * 修改冻存管历史
     */
    @Log(title = "冻存管历史 ", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TubeHistory tubeHistory) {
        return toAjax(iTubeHistoryService.updateById(tubeHistory));
    }

    /**
     * 删除冻存管历史
     */
    @Log(title = "冻存管历史 ", businessType = BusinessType.DELETE)
    @DeleteMapping("/{tubeHisIds}")
    public AjaxResult remove(@PathVariable Long[] tubeHisIds) {
        return toAjax(iTubeHistoryService.removeByIds(Arrays.asList(tubeHisIds)));
    }
}
